//--- path where to send data var submitPath = ""; // are taken from page as hidden values var redirectPath = ""; // are taken from page as hidden values var itIsAdminSection = 0; // read out from page, if non zero page was created inside admin section, we do not need to much alerts, confirmations... //--- text for messages handled by script var online_payment_err_msg = ["
Bohužel...
Online platba neproběhla úspěšně.
","
Unfortunately...
Online payment was not successful.
"]; var confirm_delete_msg = ["Opravdu chcete odebrat účastníka z registrace?","Do you really want to delete this person?"]; var check_registration_msg = ["
STISKNUTÍM TLAČÍTKA 'POTVRDIT' BUDE VAŠE REGISTRACE ODESLÁNA.
Zobrazí se potvrzení registrace, které bude zároveň odesláno na zadanou e-mailovou adresu.
Proto si zde zkontrolujte všechny zadané údaje. Pokud něco nesouhlasí, stisknutím tlačítka 'ZRUŠIT' se můžete vrátit k formuláři a chybu opravit.

", "
Please review your entered data – you can go back by clicking 'CANCEL' and correct your entries if needed or click 'OK' to submit.
After clicking 'OK', confirmation of your registration will be displayed and sent to your e-mail address, with payment information.

"]; var registration_err_status_msg = ["
Registrace se nezdařila.
","
Registration has failed.
"]; var registration_sending_fail_msg = ["Nepodařilo se odeslat data. Zkontrolujte prosím Vaše připojení k internetu a zkuste to znovu.","Unable to send data. Please check you internet connection and try again."]; var check_registration_titel = ["Zkontrolujte prosím zadané informace před odesláním","Please check entered data before sending."]; var regSucc = ["
Děkujeme za registraci.
Registrace byla úspěšná, její potvrzení bylo zasláno na Váš e-mail '_EMAIL' a bylo jí přiřazeno identifikační číslo '_PAY_ID'.
Po kliknutí na tlačítko OK se zobrazí sumarizace vaší registrace.
", "
Thank you for your registration.
A registration number '_PAY_ID' and confirmation has been sent to '_EMAIL'.
Payment details will be displayed after you click 'OK'.
"]; var missingFieldsError = ["Doplňte prosím chybějící údaje (typ stravy pro některého z účastníků, správnost emailu...).", "Please fill in the missing data (type of food, correct email...)."]; var noAdultInRegistration = ["Registrace neobsahuje žádného účastníka ve věku 15+.", "No participant in registration in age category 15+."]; var priceError = ["Cena spočtená aplikací není správná. Pokuste se údaje zadat znovu.", "Price calculated by application is incorrect. Please check your entries and try it again."]; var emailError = ["
Nepodařilo se odeslat e-mail na adresu '_EMAIL'.
Zkontrolujte prosím správnost Vámi zadané e-mail adresy.
", "
We were unable to send an email to '_EMAIL'.
Please check the e-mail address you entered.
"]; var serverError = ["Chyba na straně serveru. Zkuste to prosím znovu.", "Error on server. Please try again."]; var editError = ["Tohle by se nemělo stát... Cena spočtená stránkou se liší od ceny uvedené v databázi. Pošlete nám prosím tuto hlášku. Děkujeme.","That must not happen... Price calculated bz page is different as price saved in database. Please send us this messsage. Thank you."]; //--- text for displaying price info var priceInfoText = ["Info o cenách","Price info"]; var dailyPriceAgeTextCs = ["Denní sazba věk 0-3","Denní sazba věk 4-7","Denní sazba věk 8-14","Denní sazba věk 15+"]; var dailyPriceAgeTextEn = ["Daily price age 0-3","Daily price age 4-7","Daily price age 8-14","Daily price age 15+"]; var dailyPriceAgeText = []; dailyPriceAgeText.push(dailyPriceAgeTextCs); dailyPriceAgeText.push(dailyPriceAgeTextEn); var sleepOnPlaceTextCs = ["Cena za jednu noc věk 0-3","Cena za jednu noc věk 4-7","Cena za jednu noc věk 8-14","Cena za jednu noc věk 15+"]; var sleepOnPlaceTextEn = ["Price for one night age 0-3","Price for one night age 4-7","Price for one night age 8-14","Price for one night age 15+"]; var sleepOnPlaceText = []; sleepOnPlaceText.push(sleepOnPlaceTextCs); sleepOnPlaceText.push(sleepOnPlaceTextEn); var arriveDiscountTextCs = ["Sleva příjezd dopoledne (pouze pro věk 8-14 a 15+)","Sleva příjezd odpoledne (pouze pro věk 8-14 a 15+)","Sleva příjezd večer (pouze pro věk 8-14 a 15+)"]; var arriveDiscountTextEn = ["Arrival discount morning (only for age 8-14 and 15+)","Arrival discount afternoon (only for age 8-14 and 15+)","Arrival discount evening (only for age 8-14 and 15+)"]; var arriveDiscountText = []; arriveDiscountText.push(arriveDiscountTextCs); arriveDiscountText.push(arriveDiscountTextEn); var departureDiscountText = ["Sleva odjezd (pouze pro věk 8-14 a 15+)","Departure discount (only for age 8-14 and 15+)"]; //--- maximal count of section with persons var idPerson = ["person_0", "person_1", "person_2", "person_3", "person_4", "person_5", "person_6", "person_7", "person_8", "person_9"]; var currency = ["CZK","EUR",""]; // last one is empty string //------------------------------------------------------ // JSON format templates //------------------------------------------------------ //--- object used for calculation of price of one person var myJsonPerson = { "fname" : "", "lname" : "", "age_category" : undefined, "price_category" : undefined, "meal" : [], "meal_category" : undefined, "meal_price" : undefined, "price_full" : undefined, "price_dsc" : undefined }; //--- json format var myJson = { "function" : "add", // updateregistration or add -> for now used only in admin sektion for editing "param" : "", // again here only for compatibility with requeted fields in json-server for editation, should contains md5 of registration "arrive_day" : undefined, "arrive_time" : undefined, "departure_day" : undefined, "early_departure" : undefined, "sleep_on_place" : undefined, "currency" : undefined, "person" : [], "price_full" : undefined, "price_dsc" : undefined, "country" : "", "email" : "" }; //--- meal prices for every meal var mealPriceCzk = [ 0,0,120,80,120,120,80,120,120,80,120,0]; var mealPriceEur = [ 0,0,0,0,0,0,0,0,0,0,0,0]; //--- array with all meal prices for both currencies var mealPrice = []; mealPrice.push(mealPriceCzk); mealPrice.push(mealPriceEur); //--- just price of breakfast, lunch, dinner for price info var mealPricesCzk = [ 80,120,120] var mealPricesEur = [ 0,0,0] var mealPrices = []; mealPrices.push(mealPricesCzk); mealPrices.push(mealPricesEur); //---each index points to arrive time and value point to first meal var allowedMealToDay = []; var allowedMealToDay0 = [0,1,2]; allowedMealToDay.push(allowedMealToDay0); var allowedMealToDay1 = [3,4,5]; allowedMealToDay.push(allowedMealToDay1); var allowedMealToDay2 = [6,7,8]; allowedMealToDay.push(allowedMealToDay2); var allowedMealToDay3 = [9,10,11]; allowedMealToDay.push(allowedMealToDay3); //--------------------------------------------------------- // First day arrival time correction definition: defines amounth of money which will be substracted from price //--------------------------------------------------------- //--- corrDailySupportedCzk (same full and dsc)[0-2 arrival time] var corrDailySupportedCzk = [ 0,0,100]; //--- corrDailyNormalFullCzk[0-2 arrival time] var corrDailyNormalFullCzk = corrDailySupportedCzk; //--- corrDailyNormalDscCzk[0-2 arrival time] var corrDailyNormalDscCzk = corrDailySupportedCzk; //--- corrDailySurplusFullCzk[0-2 arrival time] var corrDailySurplusFullCzk = corrDailySupportedCzk; //--- corrDailySurplusDscCzk[0-2 arrival time] var corrDailySurplusDscCzk = corrDailySupportedCzk; //--- corrDscCzk[0-2 price category][0-2 arrival time] var corrDscCzk = []; corrDscCzk.push(corrDailySupportedCzk); corrDscCzk.push(corrDailyNormalDscCzk); corrDscCzk.push(corrDailySurplusDscCzk); //--- corrFullCzk[0-2 price category][0-2 arrival time] var corrFullCzk = []; corrFullCzk.push(corrDailySupportedCzk); corrFullCzk.push(corrDailyNormalFullCzk); corrFullCzk.push(corrDailySurplusFullCzk); //--- corrDailySupportedEur (same full and dsc)[0-2 arrival time] var corrDailySupportedEur = []; //--- corrDailyNormalFullEur[0-2 arrival time] var corrDailyNormalFullEur = []; //--- corrDailyNormalDscEur[0-2 arrival time] var corrDailyNormalDscEur = []; //--- corrDailySurplusFullEur[0-2 arrival time] var corrDailySurplusFullEur = []; //--- corrDailySurplusDscEur[0-2 arrival time] var corrDailySurplusDscEur = []; //--- corrDscCzk[0-2 price category][0-2 arrival time] var corrDscEur = []; corrDscEur.push(corrDailySupportedEur); corrDscEur.push(corrDailyNormalDscEur); corrDscEur.push(corrDailySurplusDscEur); //--- corrFullCzk[0-2 price category][0-2 arrival time] var corrFullEur = []; corrFullEur.push(corrDailySupportedEur); corrFullEur.push(corrDailyNormalFullEur); corrFullEur.push(corrDailySurplusFullEur); //--- corrDsc[0-1 currency][0-2 price category][0-2 arrival time] var corrDsc = []; corrDsc.push(corrDscCzk); corrDsc.push(corrDscEur); //--- corrFull[0-1 currency][0-2 price category][0-2 arrival time] var corrFull = []; corrFull.push(corrFullCzk); corrFull.push(corrFullEur); //--------------------------------------------------------- // Last day departure time correction definition: defines amounth of money which will be substracted from price //--------------------------------------------------------- //--- corrDepartureSupportedCzk (same full and dsc) var corrDepartureSupportedCzk = 100; //--- corrDepartureNormalFullCzk var corrDepartureNormalFullCzk = corrDepartureSupportedCzk; //--- corrDepartureNormalDscCzk var corrDepartureNormalDscCzk = corrDepartureSupportedCzk; //--- corrDepartureSurplusFullCzk var corrDepartureSurplusFullCzk = corrDepartureSupportedCzk; //--- corrDepartureSurplusDscCzk var corrDepartureSurplusDscCzk = corrDepartureSupportedCzk; //--- corrDepartureDscCzk[0-2 price category] var corrDepartureDscCzk = []; corrDepartureDscCzk.push(corrDepartureSupportedCzk); corrDepartureDscCzk.push(corrDepartureNormalDscCzk); corrDepartureDscCzk.push(corrDepartureSurplusDscCzk); //--- corrDepartureFullCzk[0-2 price category] var corrDepartureFullCzk = []; corrDepartureFullCzk.push(corrDepartureSupportedCzk); corrDepartureFullCzk.push(corrDepartureNormalFullCzk); corrDepartureFullCzk.push(corrDepartureSurplusFullCzk); //--- EUR section //--- corrDepartureSupportedEur (same full and dsc) var corrDepartureSupportedEur = 0; // ToDo: not supported now //--- corrDepartureNormalFullEur var corrDepartureNormalFullEur = corrDepartureSupportedEur; //--- corrDepartureNormalDscEur var corrDepartureNormalDscEur = corrDepartureSupportedEur; //--- corrDepartureSurplusFullEur var corrDepartureSurplusFullEur = corrDepartureSupportedEur; //--- corrDepartureSurplusDscEur var corrDepartureSurplusDscEur = corrDepartureSupportedEur; //--- corrDepartureDscEur[0-2 price category] var corrDepartureDscEur = []; corrDepartureDscEur.push(corrDepartureSupportedEur); corrDepartureDscEur.push(corrDepartureNormalDscEur); corrDepartureDscEur.push(corrDepartureSurplusDscEur); //--- corrDepartureFullEur[0-2 price category] var corrDepartureFullEur = []; corrDepartureFullEur.push(corrDepartureSupportedEur); corrDepartureFullEur.push(corrDepartureNormalFullEur); corrDepartureFullEur.push(corrDepartureSurplusFullEur); //--- corrDepartureDsc[0-1 currency][0-2 price category] var corrDepartureDsc = []; corrDepartureDsc.push(corrDepartureDscCzk); corrDepartureDsc.push(corrDepartureDscEur); //--- corrDepartureFull[0-1 currency][0-2 price category] var corrDepartureFull = []; corrDepartureFull.push(corrDepartureFullCzk); corrDepartureFull.push(corrDepartureFullEur); //---------------------------------------------------- // //---------------------------------------------------- //--- age category 0 (0-3) var dailyPriceAgeCategory0Czk = [ 0,0,0,0]; var dailyPriceAgeCategory0Eur = []; //--- age category 1 (4-7) var dailyPriceAgeCategory1Czk = [ 0,0,0,0]; var dailyPriceAgeCategory1Eur = []; //--- age category 2 (8-14) var dailyPriceAgeCategory2Czk = [ 50,50,50,50]; var dailyPriceAgeCategory2Eur = []; //--- here is dailyPriceKidsCzk[0-2 age category][0-4 day] var dailyPriceKidsCzk = []; dailyPriceKidsCzk.push(dailyPriceAgeCategory0Czk); dailyPriceKidsCzk.push(dailyPriceAgeCategory1Czk); dailyPriceKidsCzk.push(dailyPriceAgeCategory2Czk); //--- here is dailyPriceKidsEur[0-2 age category][0-4 day] var dailyPriceKidsEur = []; dailyPriceKidsEur.push(dailyPriceAgeCategory0Eur); dailyPriceKidsEur.push(dailyPriceAgeCategory1Eur); dailyPriceKidsEur.push(dailyPriceAgeCategory2Eur); //--- here is dailyPriceKids[0-1 currency][0-2 age category][0-X days] //--- age category means [0]->0-3 years, [1]->4-7 years, [2]->8-15 years var dailyPriceKids = []; dailyPriceKids.push(dailyPriceKidsCzk); dailyPriceKids.push(dailyPriceKidsEur); //--- rest is category 3 (15-) //--- discount prices in CZK var dailyPriceDscSupportedCzk = [ 100,100,100,100]; var dailyPriceDscNormalCzk = []; var dailyPriceDscSurplusCzk = []; //--- discount prices in EUR var dailyPriceDscSupportedEur = []; var dailyPriceDscNormalEur = []; var dailyPriceDscSurplusEur = []; //--- full prices in CZK var dailyPriceFullSupportedCzk = dailyPriceDscSupportedCzk; var dailyPriceFullNormalCzk = dailyPriceDscSupportedCzk; var dailyPriceFullSurplusCzk = dailyPriceDscSupportedCzk; //--- full prices in EUR var dailyPriceFullSupportedEur = []; var dailyPriceFullNormalEur = []; var dailyPriceFullSurplusEur = []; //--- CZK discount prices for every day. Example dailyPriceDscCzk[0-2 price category][0-x days] var dailyPriceDscCzk = []; dailyPriceDscCzk.push(dailyPriceDscSupportedCzk); dailyPriceDscCzk.push(dailyPriceDscNormalCzk); dailyPriceDscCzk.push(dailyPriceDscSurplusCzk); //--- EUR discount prices for every day. Example dailyPriceDscCzk[0-2 price category][0-x days] var dailyPriceDscEur = []; dailyPriceDscEur.push(dailyPriceDscSupportedEur); dailyPriceDscEur.push(dailyPriceDscNormalEur); dailyPriceDscEur.push(dailyPriceDscSurplusEur); //--- over night price for all age categories var dailySleepOnPlaceCzk = [ 0,0,50,100]; var dailySleepOnPlaceEur = []; //--- array with discount prices for both currencies and price category. Example: dailyPriceDcs[0-1 currency][0-2 price category][0-x days] var dailyPriceDsc = []; dailyPriceDsc.push(dailyPriceDscCzk); dailyPriceDsc.push(dailyPriceDscEur); //--- array with prices if you stay over night - one price for every day, dailySleepOnPlacePrice[0-1 currency][0-3 age category] var dailySleepOnPlacePrice = []; dailySleepOnPlacePrice.push(dailySleepOnPlaceCzk); dailySleepOnPlacePrice.push(dailySleepOnPlaceEur); //--- CZK full prices for every day. Example dailyPriceFullCzk[0-2 price category][0-4 day] var dailyPriceFullCzk = []; dailyPriceFullCzk.push(dailyPriceFullSupportedCzk); dailyPriceFullCzk.push(dailyPriceFullNormalCzk); dailyPriceFullCzk.push(dailyPriceFullSurplusCzk); //--- EUR full prices for every day. Example dailyPriceFullEur[0-2 price category][0-4 day] var dailyPriceFullEur = []; dailyPriceFullEur.push(dailyPriceFullSupportedEur); dailyPriceFullEur.push(dailyPriceFullNormalEur); dailyPriceFullEur.push(dailyPriceFullSurplusEur); //--- array with full prices for both currencies and price category. Example: dailyPriceFull[0-1 currency][0-2 price category][0-4 day] var dailyPriceFull = []; dailyPriceFull.push(dailyPriceFullCzk); dailyPriceFull.push(dailyPriceFullEur); //---------------------------------------------------- // @brief: Return lang get param from url // @param[input]: none // @return: 0->cs(or get param not present = dfault),1->en //---------------------------------------------------- function GetLangIndex(){ var results = new RegExp('[\?&]lang=([^&#]*)').exec(window.location.href); if(results != null && results[1]<2) { return results[1]; } else { return 0; } } function GetLangLocale(){ if(GetLangIndex()) { return 'en'; } else { return 'cs'; } } //---------------------------------------------------- // @brief: Process response from PHP server // Displasy message from server. // @param[input]: data javascript object, allready parsed json response from PHP server // data.status: 0=OK,1=some mandatory fields are empty,2=price from form does not match with price from server, // 3=unable to send email,4=other error in PHP script // data.md5: md5 hash for retrieving registration from server // data.pay_id: registration id // @param[input]: textStatus: 'success' or 'fail' // @param[input]: jqXHR // @return: nothing //---------------------------------------------------- function ProcessReponseFomServer(data, textStatus, jqXHR) { var errString = registration_err_status_msg[GetLangIndex()]; //--- this string will be used when sending has failed var resp = errString + registration_sending_fail_msg[GetLangIndex()]; var redirect = false; if(textStatus == 'success') { // sending successfull if("updateregistration" == myJson.function) { window.location.assign(redirectPath + "md5=" + myJson.param + "&lang=" + GetLangIndex()); } else { if("addadmin" == myJson.function) { window.location.assign(redirectPath + "md5=" + data.md5 + "&lang=" + GetLangIndex()); } else { var msg = [regSucc[GetLangIndex()].replace('_EMAIL',data.email).replace('_PAY_ID',data.pay_id), errString + missingFieldsError[GetLangIndex()], errString + priceError[GetLangIndex()], errString + emailError[GetLangIndex()].replace('_EMAIL',data.email), errString + serverError[GetLangIndex()], errString + noAdultInRegistration[GetLangIndex()], ]; if(data.status < msg.length ) { resp = msg[data.status]; if(data.status == 0) { redirect = true; } } else { resp = errString; } } } } if("updateregistration" != myJson.function && "addadmin" != myJson.function) { //alert(resp); bootbox.alert({ locale : GetLangLocale(), message: resp, callback: function(){ if(true == redirect) window.location.assign(redirectPath + "md5=" + data.md5 + "&lang=" + GetLangIndex()); } }); } } //---------------------------------------------------- // Calculate price fo person and check choosen meal if not out of range // @param[input]: common: object with necessary information for calculation // @param[input]: index: index of person (0-9), all infos for requested person in DOM have suffix '_index' // @param[ouput]: person object. // @return: If unable calculate, return false, but prices in json are set to 0 //---------------------------------------------------- function CalculatePriceForPerson(index,common,person) { var dayIndex; var retval = true; //--- clear price calculation person.meal_price = person.price_dsc = person.price_full = 0; //--- set the names person.fname = $(":input[name='fname_" + index + "']").val(); person.lname = $(":input[name='lname_" + index + "']").val(); $(':input:checked', "#" + idPerson[index]).each(function() { switch ($(this).attr('name')) { //--- calculate meal case "meal_" + index : if( (person.age_category == undefined || common.early_departure == undefined || common.arrive_day == undefined || common.arrive_time == undefined || common.departure_day == undefined || //--- check if this meal is not out of range of choosen days (arrive day depends on arrive time, departure always whole) $(this).val() < allowedMealToDay[common.arrive_day][common.arrive_time] || $(this).val() > allowedMealToDay[common.departure_day][2] || //--- if early departure is choosen, allow only brekfast on last day (common.early_departure != 0 && $(this).val() > allowedMealToDay[common.departure_day][0])) && //--- uncheck and do not calculate price only if meal is not already disabled, otherwise somebody can remove already ordered meal //--- User should pay for it even will not participate (0 == $(this).prop('disabled'))) { $(this).prop('checked', false); // uncheck it -> not posssible } else { // meal is allowed, add it person["meal_price"] += mealPrice[common.currency][$(this).val()]; person.meal.push($(this).val()); } break; //--- take meal_category case "meal_category_" + index : person.meal_category = $(this).val(); break; //--- take age case "age_category_" + index : person.age_category = $(this).val(); break; //--- take price category case "price_category_" + index : person.price_category = $(this).val(); break; } }); //--- check undefined values if(common.early_departure != undefined && common.sleep_on_place != undefined && person.price_category != undefined && person.age_category != undefined && common.arrive_day != undefined && common.departure_day != undefined && common.arrive_time != undefined) { for(dayIndex = common.arrive_day; dayIndex <= common.departure_day; dayIndex++) { // If age index points into kids, we have simplified the array of prices. Therefore here is used different index method for adults and kids. if(person.age_category < dailyPriceKids[common.currency].length) { person.price_dsc = person.price_full += dailyPriceKids[common.currency][person.age_category][dayIndex]; } else { person.price_dsc += dailyPriceDsc[common.currency][person.price_category][dayIndex]; person.price_full += dailyPriceFull[common.currency][person.price_category][dayIndex]; } } //--- add price for sleep on place var additionFee = common.sleep_on_place; additionFee = additionFee * (common.departure_day - common.arrive_day) * dailySleepOnPlacePrice[common.currency][person.age_category]; person.price_dsc += additionFee; person.price_full += additionFee; //--- create correction according arrive time //--- and do it for kids //--- originaly it was like this: //if(common.arrive_day > 0 && common.arrive_day <= common.departure_day && person.age_category > 2) { if(common.arrive_day <= common.departure_day && person.age_category >= 2) { if(person.price_dsc){ person.price_dsc -= corrDsc[common.currency][person.price_category][common.arrive_time]; } if(person.price_full){ person.price_full -= corrFull[common.currency][person.price_category][common.arrive_time]; } //--- create correction acording departure time. We can do it via multiplication, because if is not choosed, value is 0, otherwise is 1 if(person.price_dsc){ person.price_dsc -= common.early_departure * corrDepartureDsc[common.currency][person.price_category]; } if(person.price_full){ person.price_full -= common.early_departure * corrDepartureFull[common.currency][person.price_category]; } } } else { retval = false; } return retval; } //---------------------------------------------------- // Refresh all prices // Check if departure day is not earlier as arrive day //---------------------------------------------------- function RefreshPrices() { var i; myJson.price_dsc = myJson.price_full = 0; myJson.person.length = 0; var person = []; var somethingMissing = false; // if we are not able calculate price for any person, set to true to do not display complete price var thisPersonIsOk = false; var personMealPrice, personTicketPriceDsc, personTicketPriceFull = ""; //--- filling up the common part myJson.arrive_day = $(":input[name='arrive_day']:checked").val(); myJson.arrive_time = $(":input[name='arrive_time']:checked").val(); myJson.departure_day = $(":input[name='departure_day']:checked").val(); myJson.early_departure = $(":input[name='early_departure']:checked").val(); myJson.currency = $(":input[name='currency']:checked").val(); myJson.email = $(":input[name='email']").val(); myJson.country = $(":input[name='country']").val(); myJson.sleep_on_place = $(":input[name='sleep_on_place']:checked").val(); //--- check wrong setting - arrive and departure days if(myJson.arrive_day != undefined && myJson.departure_day != undefined) { if(myJson.arrive_day > myJson.departure_day) { $(":input[name='arrive_day']").prop('checked',false); myJson.arrive_day = undefined; } //--- if departure day is same as arrive day, earlier departure and stay over night must be disabled if(myJson.arrive_day == myJson.departure_day) { if(myJson.early_departure != undefined) { $(":input[name='early_departure'][value=0]").prop("checked", true); myJson.early_departure = 0; } if(myJson.sleep_on_place != undefined) { $(":input[name='sleep_on_place'][value=0]").prop("checked", true); myJson.sleep_on_place = 0; } } } for (i = 0; i < idPerson.length; i++) { //--- check if element exists if ($("#" + idPerson[i]).length != 0) { //--- function is called also after document is loaded because it could be editation and we need to display price. //--- therefore check here remove button and display it. if(0 != i) { $("#" + idPerson[i]).find('.remove-button').css('display','block'); } person[i] = JSON.parse(JSON.stringify(myJsonPerson)); thisPersonIsOk = CalculatePriceForPerson(i,myJson,person[i]); myJson.person.push(person[i]); // we have to push in, otherwise the index in array does not match with idPerson index if(true == thisPersonIsOk) { //--- display meal price personMealPrice = myJson.person[i].meal_price + " " + currency[myJson.currency]; //--- display discount price personTicketPriceDsc = myJson.person[i].price_dsc + " " + currency[myJson.currency]; //--- display full price personTicketPriceFull = myJson.person[i].price_full + " " + currency[myJson.currency]; myJson.price_dsc += myJson.person[i].price_dsc + myJson.person[i].meal_price; myJson.price_full += myJson.person[i].price_full + myJson.person[i].meal_price; } else { somethingMissing = true; personMealPrice = personTicketPriceDsc = personTicketPriceFull = ""; } //--- display meal price $(":input[name='meal_price_" + i + "']", "#" + idPerson[i]).val(personMealPrice); //--- display discount price $(":input[name='ticket_price_dsc_" + i + "']", "#" + idPerson[i]).val(personTicketPriceDsc); //--- display discount price $(":input[name='ticket_price_full_" + i + "']", "#" + idPerson[i]).val(personTicketPriceFull); } } //--- display whole price only if everything filled OK if(false == somethingMissing) { $('#price_dsc_id').val(myJson.price_dsc + " " + currency[myJson.currency]); $('#price_full_id').val(myJson.price_full + " " + currency[myJson.currency]); } else { $('#price_dsc_id').val(""); $('#price_full_id').val(""); } } //-------------------------------------------------- // Find get param in url //-------------------------------------------------- function FindGetParam(name){ var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); if (results==null) { return null; } else { return results[1] || 0; } } //---------------------------------------------------- // MAIN HANDLER //---------------------------------------------------- $(function () { var err = FindGetParam('err'); if(err == 0x05) { // see definition of errors in settings.php bootbox.alert(online_payment_err_msg[GetLangIndex()]); } // it is here, becasue this script is also used when page is prefilled with values by editation -> we need fill prices RefreshPrices(); if(0 != $('#price_full_from_db_id').length && 0 != $('#price_dsc_from_db_id').length){ if((parseInt($('#price_full_from_db_id').val()) != parseInt($('#price_full_id').val())) || (parseInt($('#price_dsc_from_db_id').val()) != parseInt($('#price_dsc_id').val()))) { bootbox.alert(editError[GetLangIndex()] + "
'" + $('#price_dsc_from_db_id').val() + "' x '" + $('#price_dsc_id').val() + "'
'" + $('#price_full_from_db_id').val() + "' x '" + $('#price_full_id').val() + "'"); } } //--- check if we are called from admin section if(0 != $('#it_is_admin_section_id').length) { itIsAdminSection = $('#it_is_admin_section_id').val(); } //--- try to find md5 of registration if are in edit mode if(0 != $('#md5_id').length && "" != $('#md5_id').val()) { myJson.param = $('#md5_id').val(); myJson.function = "updateregistration"; }else{ if(0!=itIsAdminSection){ myJson.function = "addadmin"; } } //--- retrieving paths for sending form if(0 != $('#submit_path_id').length) { submitPath = $('#submit_path_id').val(); } if(0 != $('#redirect_path_id').length) { redirectPath = $('#redirect_path_id').val(); } // end of part added for editation $(':input').on('click', function() { RefreshPrices(); }) $('#price_info').on('click',function() { var priceInfo = "

" + priceInfoText[GetLangIndex()] + "

"; priceInfo += 'Snídaně: ' + mealPrices[myJson.currency][0] + ' ' + currency[myJson.currency] + '
'; priceInfo += 'Oběd: ' + mealPrices[myJson.currency][1] + ' ' + currency[myJson.currency] + '
'; priceInfo += 'Večeře: ' + mealPrices[myJson.currency][2] + ' ' + currency[myJson.currency] + '
'; //--- daily prices for(i=0; i: "; if (i<3) { // kids category priceInfo += dailyPriceKids[myJson.currency][i][0]; } else { // adult category, which is more complicated, now show FULL priceInfo += dailyPriceFull[myJson.currency][myJson.person[0].price_category][0]; // last [0] is first day->all days have the same price } priceInfo += " " + currency[myJson.currency] + "
"; } //--- time arrive corrections for(i=0; i: " + corrFull[myJson.currency][myJson.person[0].price_category][i] + " " + currency[myJson.currency] + "
"; } //---sleep on place info for(i=0; i: "; priceInfo += dailySleepOnPlacePrice[myJson.currency][i] + " " + currency[myJson.currency] + "
"; } //--- departure time correction priceInfo += "" + departureDiscountText[GetLangIndex()] + ": " + corrDepartureFull[myJson.currency][myJson.person[0].price_category] + " " + currency[myJson.currency] + "
"; bootbox.alert(priceInfo); }); //--------------------------------------------------- // Json test //--------------------------------------------------- /* $('#form-registrace').on('submit', function(e){ e.preventDefault(); bootbox.confirm({ title: "This is a prompt with a date input!", message: "test", locale : 'cs', callback: function (result) { console.log(result); } }); console.log($('#form-registrace').serialize()); }); //*/ //$('_#submit_id').on('click', function () { //------------------------------------------------------- // Cancel if it a editation //------------------------------------------------------- $('#cancel_id').on('click', function () { //alert(redirectPath + "md5=" + myJson.param + "&lang=" + GetLangIndex()); window.location.assign(redirectPath + "md5=" + myJson.param + "&lang=" + GetLangIndex()); }); //------------------------------------------------------- // Save changes or create new one //------------------------------------------------------- $('#form-registrace').on('submit', function(e){ e.preventDefault(); var i = 0; var text = check_registration_msg[GetLangIndex()]; //--- if it is editation, skip confirmation, just be free... if("updateregistration" == myJson.function || "addadmin" == myJson.function) { $.post(submitPath + "lang=" + GetLangIndex(),JSON.stringify(myJson), function(data, textStatus, jqXHR) { ProcessReponseFomServer(data, textStatus, jqXHR); }, 'json').fail(function(jqXHR, textStatus, errorThrown) { ProcessReponseFomServer(null, 'fail', null); }); } else { $.each(myJson, function(key,value) { if(key == "person") { $.each(value, function(key,value) { // display Ucastik X: fname lname text += $('#person_' + i + '_label').text() + ": " + value.fname + " " + value.lname + "\n" + "
"; i++; }); } else { if(key == 'country' || key == 'email') { text += $('#'+key+'_label').text() + ": "; if(key == 'email'){ text += "" + value + "\n
"; } else { text += value + "\n
"; } } else { if(key == 'price_dsc' || key == 'price_full') { //--- do not display discount price if discount field is not displayed in form, because is over date if(key == 'price_full' || (key == 'price_dsc' && $('#price_dsc_id').css('display') != 'none' && $('#price_dsc_id').closest('div').css('display') != 'none')) { text += $('#'+key+'_label').text() + ": " + value + " " + $('#currency_'+myJson.currency).text() + "\n" + "
"; } } else { if( $('#'+key+'_label').text() != "" ) { text += $('#'+key+'_label').text() + ": " + $('#'+key+'_'+value).text() + "\n" + "
"; } } } } }); bootbox.confirm({ title: check_registration_titel[GetLangIndex()], message: text, locale : GetLangLocale(), callback: function (result) { if(result){ $.post(submitPath + "lang=" + GetLangIndex(),JSON.stringify(myJson), function(data, textStatus, jqXHR) { ProcessReponseFomServer(data, textStatus, jqXHR); }, 'json').fail(function(jqXHR, textStatus, errorThrown) { ProcessReponseFomServer(null, 'fail', null); }); } } }); } }); //---------------------------------------------------- // Event add new person //---------------------------------------------------- $('#add_person_id').on('click', function () { var i; var $newPerson; for (i = 0; i < idPerson.length; i++) { //--- find first unused person's element if ($("#" + idPerson[i]).length == 0) { $newPerson = $('#person_0').clone(true); $newPerson.attr('id', idPerson[i]); $newPerson.css('display','none'); $newPerson.find('#person_0_label').each(function () { $(this).attr('id', idPerson[i] + "_label"); }); $newPerson.find('.remove-button').css('display','block'); //--- replace visible number of person $newPerson.find('h3').each(function () { $(this).text($(this).text().replace("1",i+1)); }); //--- Clear inputs and rename form elements $newPerson.find(':input').each(function () { $(this).prop('name', $(this).prop('name').replace("0",i)); switch($(this).attr('type')) { case "text" : $(this).val(''); break; case "radio" : case "checkbox" : if($(this).css('display') != 'none') { $(this).prop('checked',false); } break; } }); $newPerson.insertAfter("#" + idPerson[i-1]); $newPerson.slideDown(1000); break; } } // disable add person button if we are full if(i == idPerson.length - 1) { $('#add_person').hide(); } RefreshPrices(); }); //---------------------------------------------------- // Event remove person //---------------------------------------------------- $('.remove-button').on('click',function () { var i; var myId = $(this).closest('div').attr('id'); bootbox.confirm( { title: confirm_delete_msg[GetLangIndex()], message: confirm_delete_msg[GetLangIndex()], locale : GetLangLocale(), callback: function (result) { if(result) { $('#' + myId).hide('slow',function () { //--- resync rest of people elements $(this.remove()); for (i = 0; i < idPerson.length; i++) { if (idPerson[i] == myId) { if ($("#" + idPerson[i+1]).length != 0) { //--- element is here, change its id to my already removed $("#" + idPerson[i+1]).attr('id',myId); //--- rename person count $("#" + myId + " h3").each(function() { $(this).text($(this).text().replace(i+2,i+1)); }); //--- rename form elements $(':input', "#" + myId).each(function () { $(this).prop('name', $(this).prop('name').replace(i+1,i)); }); //--- change others id inside elemement $("#" + idPerson[i+1] + "_label").attr('id', myId + "_label"); myId = idPerson[i+1]; } } }; //--- always anable add person button $('#add_person').show(); //--- refresh prices RefreshPrices(); }); } } }); }); });